#include("/common/layout/bootstrap_form_layout.html")
#@layout()

#define title()     
#(jxrb.message(actionName,"systemOrganize"))#(systemOrganize.organize_name ??)
#end

#define head()
#include("/common/layout/ztree_check_layout.html",treeDataUrl=jxwebpath.item+"organize/treeData/"+(systemOrganize.organize_id ??),treeLoadOkFunction="setOldOrganizeid();")
<script>
  seajs.use(["ztree", "jx_msgbox_plus", "#(jxwebpath.js)staff", "action_tree", "jx_pinyin", "jac", "jx_check"], function ($, msgbox, staff, at, jxpy)
  {
    $(function ()
    {
      jxpy({nameObject: "#organizeName", codeObject: "#organizeCode"});
      var action = '#(action)';
      if (action == "added") {
        at.setViewNum('#(systemOrganize.organize_id ??)');
      } else {
        setTimeout('refreshTree("../areaTreeData/#(systemOrganize.organize_id ??)-#(systemOrganize.area_id ??)")', 1000);
      }

      $("#b_submit").on("click", function ()
      {
        if (!jxCheck.check()) {
          return false;
        }
        $("#sub_area_id").val(getCheckedNodes());
        msgbox.confirm({url: "#(controllerKey)#(action)/"},
        function ()
        {
          msgbox.close();
          window.parent.refreshTree($("#parentId").val());
          clearForm();
        }, function ()
        {
          if (msgbox.messageType != 2)
            returnInfo();
        });
      });
    });

    function setOldOrganizeid()
    {
      $("#old_sub_area_id").val(getCheckedNodes());
    }
    var action = '#(action)';
    function clearForm()
    {
      if (action == 'added')
      {
        $("#viewNum").val(parseInt($("#viewNum").val()) + 1);
        $("#organizeName").val("");
        $("#organizeCode").val("");
        $("#phone").val("");
        $("#eMail").val("");
        $("#IM").val("");
        ztreeObjct.checkAllNodes(false);
      }
    }
    function changeOrganize()
    {
      at.setViewNum($("#parentId").val());
    }
    function changeArea()
    {
      refreshTree("#(controllerKey)areaTreeData/#(systemOrganize.organize_id ??)-" + $("#areaId").val());
    }

    $("#b_return").on("click", function () {
      if (action == 'added') {
        location.href = "#(backurl)";
      } else {
        returnInfo()
      }
    });

    function returnInfo()
    {
      var parentId = $("#parentId").val();
      if (parentId == "") {
        location.href = "#(controllerKey)1-1"
      } else {
        location.href = "#(controllerKey)2-" + parentId;
      }
    }
    window.deleteData = staff.deleteData;
    window.deletePhone = staff.deletePhone;
    window.deleteEmail = staff.deleteEmail;
    window.deleteIM = staff.deleteIM;
    window.addPhones = staff.addPhones;
    window.addEmails = staff.addEmails;
    window.addIMs = staff.addIMs;
    window.addDatas = staff.addDatas;
    window.addFields = staff.addFields;
    window.changeArea = changeArea;
    window.changeOrganize = changeOrganize;
    window.setOldOrganizeid = setOldOrganizeid;
  });
</script>
#end

#define form()

#include("info.html")
#end

#define formAfter()
<center>
  #jx_button({value:"action.save",class:"btn btn-primary"})&nbsp;&nbsp;&nbsp;&nbsp;
  #jx_button({value:"action.return",id:"b_return",class:"btn btn-danger"})
</center>
#end